/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package services;

import java.io.PrintStream;

import model.Constants;

import com.google.gdata.client.uploader.ProgressListener;
import com.google.gdata.client.uploader.ResumableHttpFileUploader;

/**
 * A {@link ProgressListener} implementation to track upload progress.
 * The listener can track multiple uploads at the same time.
 */
public class FileUploadProgressListener implements ProgressListener {
	
	private int status;
	private int progress = 0;

	
	public synchronized void progressChanged(ResumableHttpFileUploader uploader)
    {
      switch(uploader.getUploadState()) {
        case COMPLETE:
          this.setStatus(Constants.UPLOAD_COMPLETE);
          break;
        case CLIENT_ERROR:
        	this.setStatus(Constants.UPLOAD_CLIENT_ERROR);
          break;
        case IN_PROGRESS:
        	this.setStatus(Constants.UPLOAD_IN_PROGRESS);
              Double doubleProgress=(uploader.getProgress() * 100);
              this.setProgress(doubleProgress.intValue());
          break;
        case NOT_STARTED:
        	this.setStatus(Constants.UPLOAD_NOT_STARTED);
          break;
      }
    } 
	
	private void setStatus(int status){
		this.status = status;
	}
	
	public int getStatus(){
		return this.status;
	}

	public int getProgress() {
		return progress;
	}

	private void setProgress(int progress) {
		this.progress = progress;
	}
	
	
}

